'''
Author: cw
Date: 2025-08-21
Description: ...
'''
from datetime import datetime

from modules.data_models import ProcessTask
from modules.image_mota_provider import ImageMotaProvider
# from modules.image_local_provider import ImageLocalProvider


def get_provider(provider: str):
    """provider map"""
    mp = {
        # 'local': ImageLocalProvider,
        'mota': ImageMotaProvider
    }
    if provider not in mp:
        raise ValueError(f"Unknown provider code: {provider}")
    provider_cls = mp[provider]
    return provider_cls()



async def build(task: ProcessTask):
    """生成图片（测试/本地调用用）
    返回 Base64 编码的图片字符串
    """
    start_time = datetime.now()
    provider = get_provider(task.provider)
    image = await provider.run(task)
    end_time = datetime.now()
    return {
        'image': image,
        'start_time': start_time.strftime("%Y-%m-%d %H:%M:%S"),
        'end_time': end_time.strftime("%Y-%m-%d %H:%M:%S"),
        'cost': (end_time - start_time).total_seconds()
    }
